package com.ofhb.webapp.client.utils;

import java.util.HashMap;

import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.ofhb.webapp.shared.dto.CityDTO;
import com.ofhb.webapp.shared.dto.LookupDataDTO;

public class DataCache {

	public static LookupDataDTO lookupDataDTO;

	private static MultiWordSuggestOracle cityOracle = null;
	private static HashMap<String, CityDTO> mapCityNameToId = null;

	public static MultiWordSuggestOracle getCityOracle() {
		if (cityOracle == null) {
			mapCityNameToId = new HashMap<String, CityDTO>();
			cityOracle = new MultiWordSuggestOracle();
			for (CityDTO cityDTO : lookupDataDTO.getListCityDTO()) {
				String cityState = cityDTO.getName();

				if(cityDTO.getState() != null && cityDTO.getState().trim().length() > 0) {
					cityState = cityState + ", " + cityDTO.getState();
				}
				
				cityOracle.add(cityState);
				mapCityNameToId.put(cityState, cityDTO);
			}
		}
		return cityOracle;
	}

	public static CityDTO getCityDTO(String cityName) {
		return mapCityNameToId.get(cityName);
	}
}
